package com.gaogzhen.threadPool.wokerThread;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Slf4j(topic = "c.HungerPhenomenon")
public class HandleHungerPhenomenon {
    static final List<String> MENU = Arrays.asList("猪肉炖粉条", "宫保鸡丁", "糖醋里脊", "辣子鸡");

    static Random random = new Random();

    static String cooking() { return MENU.get(random.nextInt(MENU.size())); }

    public static void main(String[] args) {
        ExecutorService pool1 = Executors.newFixedThreadPool(1);
        ExecutorService pool2 = Executors.newFixedThreadPool(1);

        pool1.execute(() -> {
            log.debug("处理点餐。。。");
            Future<String> future = pool2.submit(() -> {
                log.debug("做菜");
                return cooking();
            });
            try {
                log.debug("上菜：{}", future.get());
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        });

        pool1.execute(() -> {
            log.debug("处理点餐。。。");
            Future<String> future = pool2.submit(() -> {
                log.debug("做菜");
                return cooking();
            });
            try {
                log.debug("上菜：{}", future.get());
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        });
    }
}
